﻿using System.Collections.Generic;
using System.Web.Script.Serialization;
using Taype.Trading.BTC.Utilities;
using System;

namespace Taype.Trading.BTC.MtGoxAPIClient.JSONObjects
{
    /// <summary>
    /// Encapsulates MtGox information wrapped in a multicurrency ticker item
    /// {"value":"5.70653","value_int":"570653","display":"$5.70653","currency":"USD"},
    /// </summary>
    public class MtGoxMultiCurrencyTickerItemDetail
    {
        
        public double value;

        public Int64 value_int;

        public string display;

        public MtGoxCurrencySymbol currency;

        public MtGoxMultiCurrencyTickerItemDetail()
        { }

        public MtGoxMultiCurrencyTickerItemDetail(double value, Int64 value_int, string display, MtGoxCurrencySymbol currency)
        {
            this.value = value;
            this.value_int = value_int;
            this.display = display;
            this.currency = currency;
        }

        public static MtGoxMultiCurrencyTickerItemDetail getObjects(string jsonDataStr)
        {
            string json = jsonDataStr;
            var serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic obj = serializer.Deserialize(json, typeof(object));
            MtGoxMultiCurrencyTickerItemDetail tk = new MtGoxMultiCurrencyTickerItemDetail();
            tk.value = double.Parse(obj.value.ToString());
            tk.value_int = Int64.Parse(obj.value_int.ToString());
            tk.display = obj.display.ToString();
            tk.currency = (MtGoxCurrencySymbol)Enum.Parse(typeof(MtGoxCurrencySymbol), obj.currency.ToString(), true);
            return tk;
        }
            
    }
}
